#pragma once
#include"hash.h"

namespace klaus
{
	template<class K,class V, class Hash = HashFunc<K>>
	class map
	{
	public:
		struct KOFT
		{
			const K& operator()(const pair<K,V>& data)
			{
				return data.first;
			}
		};
		typedef HashTable<K, pair<K, V>, KOFT,Hash> HashTable;
		struct HashNode;
		typedef typename HashTable::iterator iterator;
		iterator begin()
		{
			return ht.begin();
		}
		iterator end()
		{
			return ht.end();
		}
		pair<iterator,bool> insert(const pair<K, V>& kv)
		{
			return ht.insert(kv);
		}
		iterator find(const K& key)
		{
			return ht.find(key);
		}
		bool erase(const K& key)
		{
			return ht.erase(key);
		}
		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = ht.insert(make_pair(key, V()));
			return ret.first->second;
		}
	private:
		HashTable ht;
	};
}
